package com.mentaleye.biz.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.WorkTimeBean;
import com.mentaleye.biz.WorkTimeBiz;
import com.mentaleye.dal.model.WorktimeExample;
import com.mentaleye.dal.model.WorktimeExample.Criteria;
import com.mentaleye.service.WorkTimeService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;
@Service
public class WorkTimeBizImpl implements WorkTimeBiz {
    
	private static Logger logger = Logger.getLogger(WorkTimeBizImpl.class);
	@Autowired private WorkTimeService worktimeService;
	@Override
	public CommonResult worktimeAlledit(WorkTimeBean worktimeBean) {
		CommonResult result=null;
		try{
			result=new CommonResult();
			boolean success = true;
			boolean add = worktimeBean.getWorktimeNo() ==null;
			if(add){
				success=worktimeService.worktimeAdd(worktimeBean);				
			}else{
				success=worktimeService.worktimeEdit(worktimeBean);
			}
			result.setIsSuccess(success);
		} catch(Exception e){
			logger.error("错误", e);
		}
		return result;
	}

	@Override
	public CommonResult worktimeDrop(List<Integer> ids) {
		try{
		boolean result=true;
		WorkTimeBean worktimeBean=new WorkTimeBean();
		
		result = worktimeService.worktimeUpdateByList(ids, worktimeBean);
		return new CommonResult(result);
		
		}catch(Exception e){
			logger.error("删除异常",e);
		}
		return null;
	}

	@Override
	public void worktimequeryByPage(CommonPage commonPage) {
		worktimeService.worktimequeryByPage(commonPage);

	}

	@Override
	public WorkTimeBean queryWorktimeDate(Integer worktimeNo) {
		try {
			return worktimeService.queryWorktimeDate(worktimeNo);
		} catch (Exception e) {
			logger.error("查询异常",e);
		}
		return null;
	}

	@Override
	public List<WorkTimeBean> query(WorktimeExample example) {
		try {
			return worktimeService.query(example);
		} catch (Exception e) {
			logger.error("查询异常",e);
		}
		return null;
	}

	@Override
	public WorkTimeBean queryWorktimeDate(WorkTimeBean worktimeBean) {
		try {
			if(worktimeBean != null){
				Integer worktimeNo = worktimeBean.getWorktimeNo();
				return worktimeService.queryWorktimeDate(worktimeNo);
			}
		} catch (Exception e) {
			logger.error("查询异常",e);
		}
		return null;
		
	}

	@Override
	public CommonResult  worktimeDelete(List<Integer> ids) {
		try{
			return new CommonResult(worktimeService.worktimeDelete(ids));
		}catch(Exception e){
			logger.error("删除异常",e);
			return new CommonResult();
		}
		
	}
	@Override
	public CommonResult WorktimeNotIndelete(List<Integer> ids) {
		try{
			return new CommonResult(worktimeService.WorktimeNotIndelete(ids));	
		}catch(Exception e){
			logger.error("删除异常",e);
			return new CommonResult();
		}
		
	}

	@Override
	public WorkTimeBean queryWorktimeByMonth(String month) {
		WorktimeExample example=new WorktimeExample();
		Criteria criteria = example.createCriteria();
		criteria.andWorkMonthEqualTo(month);
		List<WorkTimeBean> beanList=null;
		WorkTimeBean workTimeBean=null;
		try {
			 beanList = worktimeService.query(example);
			 if(!beanList.isEmpty()){
				 workTimeBean=beanList.get(0);
			 }
		} catch (Exception e) {
			logger.error("查询异常",e);
		}
		return workTimeBean;
		
	}

}
